﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api.Ddl;

namespace Me.Prettyprint.Cassandra.Serializers
{
    /// <summary>
    /// CharSerializer uses bitconverter to to convert characters to bytes and back.
    /// The serializer uses UTF8 type for the comparator, so it's basically the same
    /// as a string.
    /// </summary>
    public class CharSerializer : AbstractSerializer<char>
    {
        public static CharSerializer Instance = new CharSerializer();

        public CharSerializer()
        {
        }
        public override ComparatorType GetComparatorType()
        {
            return ComparatorType.UTF8TYPE;
        }
        override public ComparatorType ComparatorType
        {
            get
            {
                return ComparatorType.UTF8TYPE;
            }
        }
        public override byte[] ToBytes(char obj)
        {
            return BitConverter.GetBytes(obj);
        }
        public override Utils.ByteBuffer ToByteBuffer(char obj)
        {
            return new ByteBuffer(ToBytes(obj));
        }
        public override char FromBytes(byte[] bytes)
        {
            return BitConverter.ToChar(bytes,0);
        }
        public override char FromByteBuffer(ByteBuffer buff)
        {
            return FromBytes(buff.GetBuffer());
        }
    }
}
